package org.gof.application
{
	import application.BallFacade;
	
	use namespace AppNS;
	use namespace SetByAppNS;
	public class RefreshDataCmd extends BaseCommand
	{
		private static const TIME_BETWEEN_REFRESH:Number = 150;
		private var app:BallFacade;
		private var _lastRefreshTime:Number = 0;
				
		public function RefreshDataCmd(): void
		{
		
		}
		
		SetByAppNS override function set application(a:BaseAppFacade):void
		{
			super.application = a;
			app = _app as BallFacade
		}
		
		public function execute(tickCount:int): void
		{
			refreshIfReady();			
		}
		
		
				
		private function get now():Number
		{
			var d:Date = new Date();
			return d.time;
		}
		
		private function get timeSinceLastRefresh():Number
		{
			return now - _lastRefreshTime;
		}
		
		private function refreshIfReady():void
		{
			if (timeSinceLastRefresh > TIME_BETWEEN_REFRESH)
			{
				refresh();
				_lastRefreshTime = now;
			}
		}
		
		
		private function refresh() : void
		{
			//trace("RefreshDataCmd.refresh")
			
				for (var cntx:int = 0; cntx < app.readProxies.length; cntx++)
				{
					var rp:BaseReadProxy = app.readProxies[cntx];
					rp.refreshAllData();
				}
		}
		
	}
}